/**
 * 暂停界面
 */

import gamePrefabMgr, { uiPreName } from "./SdkTools/gamePrefabMgr";
import gameShareAdsVideo from "./SdkTools/gameShareAdsVideo";
import gameStorage from "./SdkTools/gameStorage";
import PlayData, { GameType } from "./SdkTools/PlayData";
import storage from "./SdkTools/storage";
import SDKManager from "./plat/SDKManager";



const { ccclass, property } = cc._decorator;

@ccclass
export default class pausePanel extends cc.Component {

    @property(cc.Node)
    zhendong: cc.Node = null
    @property(cc.Node)
    yinyue: cc.Node = null
    @property(cc.Node)
    sound: cc.Node = null

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        SDKManager.getInstance().showInterstitial();
        gameShareAdsVideo.Instance.bannerAds_Show()

        this.zhendong.active = !(gameStorage.getzhendong() == 1)
        this.yinyue.active = gameStorage.getMusic() == 1
        this.sound.active = gameStorage.getSound() == 1
        PlayData.Instance.ispause = !0
    }

    start() {

    }

    protected onDisable(): void {
        PlayData.Instance.ispause = !1
    }

    // update (dt) {}

    close() {
        gameShareAdsVideo.Instance.bannerAds_Hide()
        this.node.removeFromParent(true)
    }

    replay() {
        gameShareAdsVideo.Instance.bannerAds_Hide()
        if (storage.Instance.getEnergy() <= 0) {
            //TipsManager.Instance.createTips('体力不足')
            let newnode = cc.instantiate(gamePrefabMgr.Instance.uiPre[uiPreName.addEngry])
            newnode.parent = cc.director.getScene()
            return
        }
        storage.Instance.setEnergy(storage.Instance.getEnergy() - 1)
        cc.director.emit('addengry')
        gameShareAdsVideo.Instance.recording_Video_End()
        switch (PlayData.Instance.gameType) {
            case GameType.finddifference_zhaobutong:
                cc.director.loadScene('GameScene')
                break
        }
    }

    zhendongclick() {
        this.zhendong.active = !this.zhendong.active
        if (this.zhendong.active) {
            gameStorage.setzhendong(0)
        } else {
            gameStorage.setzhendong(1)
        }
    }

    yinyueclick() {
        this.yinyue.active = !this.yinyue.active
        if (this.yinyue.active) {
            gameStorage.setMusic(1)
            cc.audioEngine.stopAll()
        } else {
            gameStorage.setMusic(0)

            switch (PlayData.Instance.gameType) {
                case GameType.finddifference_zhaobutong:
                    cc.director.emit('game_bg1')
                    break
            }


        }
    }

    soundClick() {
        this.sound.active = !this.sound.active
        if (this.sound.active) {
            gameStorage.setSound(1)
        } else {
            gameStorage.setSound(0)
        }
    }

    backToStartScene() {
        gameShareAdsVideo.Instance.recording_Video_End()
        gameShareAdsVideo.Instance.bannerAds_Hide()
        cc.director.loadScene('StartScene')
    }

}
